/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.modules.storage.entity.Member;
import com.jeesite.modules.storage.entity.VipMember;
import com.jeesite.modules.storage.service.MemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 会员Controller
 */
@Controller(value = "webmember")
@RequestMapping(value = "${adminPath}/storage/member")
public class MemberController extends BaseController {

    @Autowired
    protected MemberService memberService;

    /**
     * 查询列表
     */
    @RequestMapping(value = {"list", ""})
    public String list(Member member, Model model) {
        model.addAttribute("member", member);
        return "modules/storage/member/list";
    }

    /**
     * 查询列表数据
     */
    @RequestMapping(value = "listData")
    @ResponseBody
    public Page<Member> listData(Member member, HttpServletRequest request, HttpServletResponse response) {
        member.setPage(new Page<>(request, response));
        return memberService.findPage(member);
    }

    /**
     * 调整
     */
    @RequestMapping(value = "adjust")
    @ResponseBody
    public String adjust(String memberId,String type) {
        try{
            Member member = new Member(memberId);
            member.setType(type);
            memberService.save(member);
            return renderResult(Global.TRUE, text("调整会员等级成功！"));
        }catch (Exception ex){
            return renderResult(Global.FALSE, text(ex.getMessage()));
        }
    }
}